#include <iostream>
#include <sys/types.h>
#include <unistd.h>
#include <signal.h>


void pendingPrin(sigset_t* s)
{
  for(int i=31;i>0;i--)
  {
    if(sigismember(s,i))
    {
      std:: cout<<1;
    }
    else std::cout<<0;
  }
  std::cout<<std::endl;
  std::cout<<"----------------------------------------------"<<std::endl;
}


void handler(int signo)
{
  std::cout<<"get a signo: "<<signo<<std::endl;
}

int main()
{
  std::cout<<"my pid is: "<<getpid()<<std::endl;
  //自定义处理2信号和40信号
  signal(2,handler);
  signal(40,handler);
  sigset_t set,s;
  sigemptyset(&set);
  sigaddset(&set,2);
  sigaddset(&set,40);
  sigprocmask(SIG_BLOCK,&set,nullptr);
  
  while(true)
  {
    sigpending(&s);
    std::cout<<"pending: ";
    pendingPrin(&s);
    std::cout<<"  block: ";
    pendingPrin(&set);
    sleep(3);
  }
  return 0;
}
